import numpy
import function as func
import findFunction
import getFunction
import isFunction
from listnode import ListNode
from function import Astar


if __name__ == '__main__':
    print("请输入原始状态，格式为从左到右，从上到下，以空格隔开")
    arr = input("")   
    num = [int(n) for n in arr.split()]
    num = numpy.array(num)
    start = num.reshape(3,3)
    print("原始状态:")
    print(start)

    print("请输入目标状态，格式为从左到右，从上到下，以空格隔开")
    arr = input("")   
    num = [int(n) for n in arr.split()]
    num = numpy.array(num)
    end = num.reshape(3,3)
    print("目标状态:")
    print(end)

    Original = ListNode(val=start, cost=getFunction.getDist(start, end))
    Target = ListNode(val=end)
    Road = Astar(origin=Original, target=Target, cons_func=func.constructNext, dist_func=getFunction.getDist
                   , find_func=findFunction.findElemInList, judge_func=isFunction.IsSolvable)
    
    for i, elem in enumerate(Road):
        print('----- Node', i, '-----')
        print(elem.getVal())
        print('f(n):', elem.getFn())
    pass

